package com.test.resumeanalysis.ui.home

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import com.test.resumeanalysis.common.CommonRvAdapter
import com.test.resumeanalysis.common.CommonRvHolder
import com.test.resumeanalysis.data.model.JobInfo
import com.test.resumeanalysis.data.model.JobPost
import com.test.resumeanalysis.databinding.RvHomePostBinding

class HomeAdapter: CommonRvAdapter<JobInfo,RvHomePostBinding>() {
    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): CommonRvHolder<RvHomePostBinding> {
        // 使用Binding类解析布局设置到Holder上
        val inflate = RvHomePostBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return CommonRvHolder(inflate)
    }

    override fun onBindViewHolder(
        holder: CommonRvHolder<RvHomePostBinding>,
        position: Int,
        binding: RvHomePostBinding,
        bean: JobInfo
    ) {
        holder.binding.tvTitle.text = bean.jobname
//        holder.binding.tvFond.text = bean.wages

        holder.binding.tvRequire1.text =  bean.requirement


        holder.itemView.setOnClickListener {
            mOnItemClickListener?.onItemClick(position)
        }
    }

    //创建OnItemClickListener接口
    interface OnItemClickListener {
        fun onItemClick(position: Int)
    }

    //声明一个mItemClickListener接口
    private var mOnItemClickListener: OnItemClickListener? = null

    //添加setOnItemClickListener方法
    fun setOnItemClickListener(listener: OnItemClickListener?) {
        mOnItemClickListener = listener
    }

}